Preview - Constructing A Simple Model: Solid Diffusion

Choose measures and implement them


One way to implement the pseudo-code for the Go procedure in the previous section is in the model below. Compare it with yours, and make any changes you want. If you run the model for a few seconds, you will notice vacancies on the edge of the view disappearing and reappearing on the opposite edge of the view. This is because by default, the patches in NetLogo "wrap around." Unless we are modeling the diffusion of two half-toroids, this isn't what we want. To change this setting:

  • If you are using NetLogo Desktop click the Settings button on the top right of the interface and uncheck the boxes for "World wraps horizontally" and "World wraps vertically."
  • If you are using NetLogo Web, go into Authoring mode, then right-click the view (the box of patches) and click "edit." Then uncheck the boxes that say "wraps horizontally" and "wraps vertically."

 

Now it is time to make some plots to check if our model matches the reference pattern. 

 


Questions

Please answer the questions below.

First we'll make a plot of the maximum diffusion distance so that you can learn how to make plots. Then you will make a plot on your own to match the reference pattern.

Right now, there is no way to create plots directly in NetLogo Web, so you'll have to use NetLogo Desktop.

For one dimensional diffusion, there is a known linear relationship between the squared diffusion distance and time. We'll make a plot of the squared maximum diffusion distance over time, and it should show an approximately linear relationship. 

To create a plot, right-click on the white area and select plot. You can also click the add button on the top of the interface with the selector next to it set to "plot." Enter this code in the Pen update command box:  plot (max([pxcor] of a-atoms) - min([pxcor] of b-atoms)) ^ 2. And change the title to Max Diffusion Distance. 

Your final plot box should look like this:

Here is what's going on in the plot command:

  • plot: plots the new point (full documentation)
  • [pxcor] of a-atoms: returns a list of the pxcor of the patch that each a-atom is on
  • max(list) and min(list): return the maximum and minimum value of a list respectively 
  • number ^ 2: squares the numberis really "to the power" so if you changed the 2 to a 3, it would cube the number.

Run the model with the new graph. Is the relationship approximately linear? Why isn't it exactly linear?


Now you will make a graph of reference pattern, shown again below for reference. There are multiple way to do this, but you may want to use a histogram. You use this command inside the Pen update commands box instead of the plot command. You can add a second line to the graph by clicking the add pen button in the plot editing pane. You also may need the set-plot-x-range command if you use a histogram.  Copy the code from you pen update commands below. 

Hint: Since we are just matching the graph qualitatively, you don't need to use concentrations. You can just use a count of the number of atoms. The next page will show one solution.


If you had any issues on this page, describe them below. If not, type something like "no problems" and continue on.


Notes

These notes will appear on every page in this lesson so feel free to put anything here you'd like to keep track of.